/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.ui.dialogs;

import java.util.Iterator;
import java.util.List;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.uml2.uml.Collaboration;
import org.eclipse.uml2.uml.CollaborationUse;
import org.eclipse.uml2.uml.NamedElement;

import com.cea.papyrus.core.utils.Debug;

/**
 * this class is used to set the role of a collaboration use.
 * 
 * @author PT202707
 */

public class ChooseRoleDialog extends ChooseDialog  implements IChooseDialog{
	
	/**
	 * 
	 */
	List allTypes=null;
	
	/**
	 * 
	 */
	Collaboration collaboration=null;
	
	/**
	 * 
	 * 
	 * @param parentShell 
	 * @param collaborationuse 
	 */
	public ChooseRoleDialog(Shell parentShell,CollaborationUse collaborationuse){
		super(parentShell);
		announce="Choose the role:";
	    collaboration= collaborationuse.getType();
		
		if (collaboration==null){
			announce=" The Collaboration is not typed!!  ";
			elementList=new String[1];
			elementList[0]="<Undefined>";
			
			return;
		}
		
		allTypes=collaboration.getRoles();
		
		
		elementList = new String[allTypes.size()];
		
		Iterator it = allTypes.iterator();
		int i=0;
		//all elements are Properties
		while( it.hasNext()){
			NamedElement ne=((NamedElement)it.next());
			elementList[i]=ne.getName()+"      ["+ ne.getQualifiedName()+"]";
			i++;
		}


	}
	
	/**
	 * 
	 * 
	 * @param parent 
	 * 
	 * @return 
	 */
	@Override
	protected Control createDialogArea(Composite parent){
		Composite comp=(Composite)super.createDialogArea(parent);
		
		return comp;
	}
	
	/**
	 * 
	 * 
	 * @param parent 
	 */
	@Override
	protected void createButtonsForButtonBar(Composite parent){
		super.createButtonsForButtonBar(parent);
		
	}
	
	/**
	 * 
	 * 
	 * @param buttonId 
	 */
	@Override
	protected void buttonPressed(int buttonId){
		super.buttonPressed(buttonId);
	}
	
	/**
	 * 
	 */
	@Override
	protected void okPressed(){
		Debug.debug(this,"ChooseDialog.okPressed "+combo.getSelectionIndex(), channel);
		int i=combo.getSelectionIndex();
		if(allTypes!=null){
			value=allTypes.get(i);
		}
		else{value=null;}
		
		super.okPressed();
	}

}
